package com.health.mapp.impl;

import java.util.Date;

import org.apache.log4j.Logger;

import com.health.db.model.UserLIST;
import com.health.db.service.user.IUserLISTService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.ModifyUserIconReq;
import com.health.mapp.bean.ModifyUserIconResp;
import com.health.mapp.utils.Response;

public class ModifyUserIconImpl implements ActionInterface{

	
	private static Logger logger = Logger.getLogger(ModifyUserIconImpl.class);

	private IUserLISTService userLISTService ;
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		// TODO Auto-generated method stub
		
		//do it bobo
		ModifyUserIconReq req=(ModifyUserIconReq) reqBean;
		ModifyUserIconResp _resp=new ModifyUserIconResp();
		String userId=req.getUserId();
		String iconUrl=req.getIconUrl();
		String iconFile=req.getIconFile();
		
		if (null==iconUrl||iconUrl.equals("")){
			_resp.setErrorCode(-1);
			_resp.setErrorMsg("头像不能为空");
		}else {
			UserLIST userList=userLISTService.selectByUserId(Long.valueOf(userId));
			if (null==userList) {
				_resp.setErrorCode(-1);
				_resp.setErrorMsg("查询不到相关用户信息");
			}else
			{
				userList.setIconUrl(iconUrl);
				//userList.setIconName(req.getIcon());
				userList.setUpdateDate(new Date());
				int result=userLISTService.updateByPrimaryKey(userList);
				logger.info("更新用户昵称结果是："+result);
				if (result>0) {
					_resp.setErrorCode(0);
					_resp.setErrorMsg("更新用户头像成功");
				}else {
					_resp.setErrorCode(-1);
					_resp.setErrorMsg("更新用户头像失败");
				}
			}
		}
		
		return _resp;
	}
	public IUserLISTService getUserLISTService() {
		return userLISTService;
	}
	public void setUserLISTService(IUserLISTService userLISTService) {
		this.userLISTService = userLISTService;
	}
	 

}
